
package cookie.delete;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.e885.log.E885Logger;

/**
 * url: http://127.0.0.1:8080/JSP/cookie/deleteGet<br>
 * <br>
 * 取得 cookie 所有的資料, 看有沒有一個名稱為 "DeleteCookie" 的 cookie
 * 
 * @author Grady.Kao
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2000-2008
 */

public class CookieDeleteGetter extends HttpServlet
{
	private static final long serialVersionUID = -5989926388798653948L;

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void service( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
	{
		E885Logger.testLog.debug( "execute CookieDeleteGetter.service() to get Cookie" );

		response.setContentType( "text/html;charset=UTF-8" );
		PrintWriter writer = response.getWriter();

		Cookie[] cookies = request.getCookies();
		if( cookies == null )
			cookies = new Cookie[ 0 ];

		for( int i = 0; i < cookies.length; i++ )
		{
			String value = URLDecoder.decode( cookies[ i ].getValue(), "UTF-8" ); 

			writer.println( "=========================================================<br>" );
			writer.println( "name:" + cookies[ i ].getName() + "<br>" ); 
			writer.println( "value:" + value + "<br>" ); 
		}

		writer.close();
	}
}
